/**
 *
 */
package corp.edu.amadeus.core.dao.impl.callback;


import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import corp.edu.amadeus.core.dao.impl.Parameter;


/**
 * @author Eduardo Perrino.
 *
 */
public class FindUniqueByNamedQueryCallback implements HibernateCallback {

    private String queryName;
    private Collection params;

    public FindUniqueByNamedQueryCallback(String queryName, Collection params) {
        super();
        this.queryName = queryName;
        this.params = params;
    }


    /**
     *
     */
    public Object doInHibernate(Session session) throws HibernateException,
        SQLException {

        Query query = session.getNamedQuery(queryName);
        Iterator it = params.iterator();
        while (it.hasNext()) {
            ((Parameter)it.next()).addToQuery(query);
        }
        return query.list();
    }
}
